/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeanAdmin;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;

import javax.faces.bean.SessionScoped;
import processor.ComplaintFacade;
import report.Summaryreport;
import org.primefaces.model.chart.PieChartModel;

/**
 *
 * @author maynoigi
 */
@ManagedBean
@SessionScoped
public class SummaryReportBean implements Serializable {

    @EJB
    private ComplaintFacade complaintFacade;
    private List<Summaryreport> filteredReport;
    private List<Summaryreport> summaryReport;
    private Date daily;
    private Date fromWeekly;
    private Date toWeekly;
    private Date monthly;
    private PieChartModel pieModel = new PieChartModel();

    public ComplaintFacade getComplaintFacade() {
        return complaintFacade;
    }

    public void setComplaintFacade(ComplaintFacade complaintFacade) {
        this.complaintFacade = complaintFacade;
    }

    public PieChartModel getPieModel() {

        if (flag.equals("")) {
            summaryReport = complaintFacade.summaryReport();
            flag = "All";
        } else if (flag.equals("Daily")) {
            summaryReport = complaintFacade.summaryReportByDaily(daily);

        } else if (flag.equals("In Range")) {
            summaryReport = complaintFacade.summaryReportByWeekly(fromWeekly, toWeekly);
        }

        long total = 0;
        long wait = 0;
        long done = 0;
        for (Summaryreport summaryreport1 : summaryReport) {
            total += summaryreport1.getTotalComplaint();
            wait += summaryreport1.getTotalWait();
            done += summaryreport1.getTotalDone();
        }
  
        pieModel.set("Total Wait", wait);
        pieModel.set("Total Done", done);
        return pieModel;
    }

    public void setPieModel(PieChartModel pieModel) {
        this.pieModel = pieModel;
    }

    public Date getMonthly() {
        return monthly;
    }

    public void setMonthly(Date monthly) {
        this.monthly = monthly;
    }

    public Date getFromWeekly() {
        return fromWeekly;
    }

    public void setFromWeekly(Date fromWeekly) {
        this.fromWeekly = fromWeekly;
    }

    public Date getToWeekly() {
        return toWeekly;
    }

    public void setToWeekly(Date toWeekly) {
        this.toWeekly = toWeekly;
    }
    private String flag = "";

    public Date getDaily() {
        return daily;
    }

    public void setDaily(Date daily) {

        this.daily = daily;
    }

    public List<Summaryreport> getFilteredReport() {
        return filteredReport;
    }

    public void setFilteredReport(List<Summaryreport> filteredReport) {
        this.filteredReport = filteredReport;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public List<Summaryreport> getSummaryReport() {
        if (flag.equals("")) {
            summaryReport = complaintFacade.summaryReport();
            flag = "All";
        } else if (flag.equals("Daily")) {
            summaryReport = complaintFacade.summaryReportByDaily(daily);

        } else if (flag.equals("In Range")) {
            summaryReport = complaintFacade.summaryReportByWeekly(fromWeekly, toWeekly);
        }

        return summaryReport;
    }

    public void setSummaryReport(List<Summaryreport> summaryReport) {
        this.summaryReport = summaryReport;
    }

    public void summaryReportByDaily() {
        flag = "Daily";
    }

    public void summaryReportByWeekly() {
        flag = "In Range";
    }

    public SummaryReportBean() {
    }
}
